package iconSwingStates.StateMachine;

import iconSwingStates.LIConLauncher;

import javax.swing.JFrame;

import fr.emn.reactiveinput.SlotType;
import fr.lri.swingstates.canvas.CElement;
import fr.lri.swingstates.canvas.CStateMachine;
import fr.lri.swingstates.canvas.Canvas;

/**
 * This is the class the developer must extends in order to use SwingStates AND ICon
 * @author uribe - gaget
 */
public abstract class SMIconStateMachine extends CStateMachine{
	private Canvas canvas;
	private JFrame frame;
	private String[] pointers = new String[0];;
	
	/**
	 * All the kind of slots possible.
	 */
	public static final int NULL = SlotType.NULL; 
	public static final int BOOLEAN = SlotType.BOOLEAN;
	public static final int INT = SlotType.INT;
	public static final int DOUBLE = SlotType.DOUBLE;
	public static final int STRING = SlotType.STRING;
	public static final int OBJECT = SlotType.OBJECT;
	public static final int ANY = SlotType.ANY;

	/**
	 * Default constructor
	 * @param name the device's name
	 * @param f the frame
	 * @param c the canvas
	 * @param pointers the pointers used in this devices
	 */
	public SMIconStateMachine(String name, JFrame f, Canvas c, String[] pointers){
		this.pointers = pointers;
		init( name,  f, c);
	}

	/**
	 * Constructor where no pointers are needed
	 * @param name the device's name
	 * @param f the frame
	 * @param c the canvas
	 */
	public SMIconStateMachine(String name, JFrame f, Canvas c){
		init( name,  f, c);
	}

	/*
	 * Method which starts ICon
	 */
	private void init(String name, JFrame f, Canvas c){
		canvas  = c;
		frame = f;
		LIConLauncher.start(name, frame, canvas , this);
		attachTo(c);
	}

	@Override
	public void attachTo(CElement ce) {
		super.attachTo(ce);
		canvas = (Canvas) ce.getCanvas();
	}

	/**
	 * Returns the pointers
	 * @return the pointers in a String array
	 */
	public String[] getPointers(){
		return pointers;
	}
	
	/**
	 * Returns the state machine canvas
	 * @return the canvas
	 */
	public Canvas getCanvas(){
		return canvas;
	}
}

